<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
    <span class="layui-breadcrumb">
          <a>首页</a><a>我的客户</a><a><cite>客户详情</cite></a>
	  </span>
    <button class="layui-btn layui-btn-xs crumb-reload fr" onclick="location.reload()"><i class="layui-icon layui-icon-refresh"></i></button>
</div>
<div class="layui-fluid layadmin-homepage-fluid">
    <div class="layui-row layui-col-space8">
        <div class="layui-col-md4" style="margin-top: 30px;" >
            <div class="layadmin-homepage-panel layadmin-homepage-shadow">
                <div class="layui-card text-center">
                    <div class="layui-col-md6">
                        <div class="layadmin-homepage-pad-ver">
                            <img class="layadmin-homepage-pad-img" src="/img.jpg" width="96" height="96">
                        </div>
                    </div>
                    <div class="layui-col-md6" style="margin-top: 30px;">
                        <div class="layui-card-body">
                            <p class="layadmin-homepage-min-font" style="font-weight:bold;color: #0C0C0C;">{$student.student_name}
                                {if $student.status == '2'}
                                <a class="layui-btn layui-btn-xs layui-btn-danger">无效</a>
                                {/if}
                            </p>
                            <p class="layadmin-homepage-min-font">
                                {$student.phone}
<!--                                <i id="call" class="layui-icon layui-icon-cellphone"></i>-->
                                <i id="dial" class="layui-icon layui-icon-cellphone"></i>
                                <input type="hidden" id="d-url" value="https://ai.800ing.com/"/>
                                <input type="hidden" id="d-name" value="{$user.call_username}"/>
                                <input type="hidden" id="d-pass" value="{$user.call_password}"/>
                                <input  id="phoneno" name="phoneno" value="{$student.phone}" type="hidden" size=15 >
                            </p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row layui-col-space15" style="border-style:solid;border-color: #CCCCCC;border-width: 0 0 1px 0;">
            </div>
            <div class="layui-row layui-col-space15" style="font-size: 12px;">
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">基本信息</div>
                        <div class="layui-card-body">
                            <p class="layadmin-homepage-min-font">性别：<span style="color: #0C0C0C;" class="sex">{if $student.sex}{$student.sex}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">联系人：<span style="color: #0C0C0C;" class="customer_name">{if $student.customer_name}{$student.customer_name}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">手机号码：<span style="color: #0C0C0C;" class="guardian_phone">{if $student.guardian_phone}{$student.guardian_phone}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">更多联系人：<span style="color: #0C0C0C;" class="other">{if $student.other}{$student.other}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">电话号码：<span style="color: #0C0C0C;" class="other_phone">{if $student.other_phone}{$student.other_phone}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">跟进人：<span style="color: #0C0C0C;">{$student.course_consultant}</span></p>
                            <p class="layadmin-homepage-min-font">省市区：<span style="color: #0C0C0C;">{if $student.address}{$student.address}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">Q Q：<span style="color: #0C0C0C;" class="qq">{if $student.qq}{$student.qq}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">微信：<span style="color: #0C0C0C;" class="weixin">{if $student.weixin}{$student.weixin}{else/}--{/if}</span></p>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6">
                    <div class="layui-card">
                        <div class="layui-card-header">关键信息</div>
                        <div class="layui-card-body">
                            <p class="layadmin-homepage-min-font">客户成熟度：<span style="color: #0C0C0C;" class="intentional_grade_text">{$student.intentional_grade_text}</span></p>
                            <p class="layadmin-homepage-min-font">最后联系：<span style="color: #0C0C0C;" class="date">{if $student.follow_up_time}{$student.follow_up_time}{else/}--{/if}</span></p>
                            <p class="layadmin-homepage-min-font">下次联系：<span style="color: #0C0C0C;" class="date">{if $student.next_follow_up_time}{$student.next_follow_up_time}{else/}--{/if}</span></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md8">
            <div class="layui-fluid layadmin-message-fluid">
                <div class="layui-row" style="border-style:solid;border-color: #CCCCCC;border-width: 2px;margin-top: 15px;">
                    <div class="layui-fluid" id="LAY-component-timeline">
                        <div class="layui-col-md12">
                            <div class="layui-card-header" style="border-style:solid;border-color: #CCCCCC;border-width: 0 0 2px 0;"><span>跟进记录</span>
                                <div style="float: right;">
                                    {if $Type_Student == 5}
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="invalid">标记无效</a>
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="release">释放线索</a>
                                    {else/}
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="invalid">标记无效</a>
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="release">释放线索</a>
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="assignment">转给同事</a>
                                    <a class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius" data-type="delete">移除客户</a>
                                    {/if}
                                </div>
                            </div>
                            <form class="layui-form layui-form-pane" style="margin-top: -50px;">
                                <input type="hidden" name="student_id" id="student_id" value="{$student.id}">
                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                                    <legend style="font-size: 14px;">选填项:</legend>
                                </fieldset>

                                <div class="layui-form-item" style="margin-top: -15px;">
                                    <label class="layui-form-label" style="font-size: 14px;">兴趣点</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="interest" placeholder="兴趣点" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item" style="margin-top: -10px;">
                                    <label class="layui-form-label" style="font-size: 14px;">异议点</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="objection" placeholder="异议点" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item" style="margin-top: -10px;">
                                    <label class="layui-form-label" style="font-size: 14px;">服务介绍</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="service_introduction" placeholder="服务介绍" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item" style="margin-top: -10px;">
                                    <label class="layui-form-label" style="font-size: 14px;">跟进思路</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="next_follow_up_ideas" placeholder="下次跟进思路" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item" style="margin-top: -10px;">
                                    <label class="layui-form-label" style="font-size: 14px;">备注</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="remark" placeholder="备注" class="layui-input">
                                    </div>
                                </div>

                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: -10px;">
                                    <legend style="font-size: 14px;">勾选项（可选）：</legend>
                                </fieldset>

                                <div class="layui-form-item" style="margin-top: -15px;">
                                    <div class="layui-inline">
                                        <label class="layui-form-label" style="font-size: 14px;">未联系客户</label>
                                        <div class="layui-input-inline">
                                            <input type="checkbox" name="is_contact" lay-skin="primary" title="是">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label" style="font-size: 14px;">是KP</label>
                                        <div class="layui-input-inline">
                                            <input type="radio" name="is_kp" value="1" title="否">
                                            <input type="radio" name="is_kp" value="2" title="是">
                                        </div>
                                    </div>
                                </div>

                                <fieldset class="layui-elem-field layui-field-title" style="margin-top: -15px;">
                                    <legend style="font-size: 14px;">必选项：</legend>
                                </fieldset>

                                <div class="layui-form-item" style="margin-top: -15px;">
                                    <label class="layui-form-label" style="font-size: 14px;">客户成熟度</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="intentional_grade" value="1" title="1类">
                                        <input type="radio" name="intentional_grade" value="2" title="2类">
                                        <input type="radio" name="intentional_grade" value="3" title="3类">
                                        <input type="radio" name="intentional_grade" value="4" title="4类">
                                        <input type="radio" name="intentional_grade" value="5" title="5类">
                                        <input type="radio" name="intentional_grade" value="0" title="0类"  checked="" disabled="">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-top: -10px;">
                                    <label class="layui-form-label" style="font-size: 14px;">下次联系</label>
                                    <div class="layui-input-inline">
                                        <input type="text" style="width: 190px;" name="next_follow_up_time" id="gj" readonly lay-verify="required" placeholder="下次联系时间" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item" style="margin-top: -100px;">
                                    <div class="layui-input-block layui-input-right">
                                        <a class="layui-btn" lay-filter="formDemo" lay-submit id="content">添加</a>
                                    </div>
                                </div>
                            </form>
                            <div class="layui-row layui-col-space15" style="border-style:solid;margin-bottom:10px;border-color: #CCCCCC;border-width: 0 0 2px 0;">
                            </div>
                            <div class="layui-card">
                                <div class="layui-tab">
                                    <div class="layui-tab-content">
                                        <div class="layui-tab-item  layui-show">
                                            <div class="layui-card-body" style="margin-top: -20px;">
                                                <ul class="layui-timeline" id="addHtml">
                                                    {volist name="logs" id="v"}
                                                    <li class="layui-timeline-item">
                                                        <i class="layui-icon layui-timeline-axis"></i>
                                                        <div class="layui-timeline-content layui-text">
                                                            <h5 class="layui-timeline-title">{$v.time}</h5>
                                                            <div style="float: left;margin-right: 10px;">
                                                                <img style="width:40px;height:40px;border-radius:25px;" src="{$v.avatar}">
                                                            </div>
                                                            <div style="font-size: 12px;margin-left: 50px;">
                                                                <p>
                                                                    <span>{$v.type_text}</span><br/>
                                                                    <span style="font-weight: bold;">备注:&nbsp;&nbsp;</span>{$v.remark}
                                                                </p>
                                                                {if $v.type == 2}
                                                                <p>
                                                                    {if $v.interest}<span style="font-weight: bold;">兴趣点:&nbsp;&nbsp;</span>{$v.interest}&nbsp;&nbsp;{/if}
                                                                    {if $v.objection}<span style="font-weight: bold;">异议点:&nbsp;&nbsp;</span>{$v.objection}&nbsp;&nbsp;{/if}
                                                                    {if $v.service_introduction}<span style="font-weight: bold;">服务介绍:&nbsp;&nbsp;</span>{$v.service_introduction}&nbsp;&nbsp;{/if}
                                                                    {if $v.next_follow_up_ideas}<span style="font-weight: bold;">跟进思路:&nbsp;&nbsp;</span>{$v.next_follow_up_ideas}&nbsp;&nbsp;{/if}
                                                                    {if $v.is_contact}<span style="font-weight: bold;">未联系客户:&nbsp;&nbsp;</span>{$v.is_contact_text}&nbsp;&nbsp;{/if}
                                                                    {if $v.is_kp}<span style="font-weight: bold;">是KP:&nbsp;&nbsp;</span>{$v.is_kp_text}&nbsp;&nbsp;{/if}
                                                                    {if $v.intentional_grade}<span style="font-weight: bold;">客户成熟度:&nbsp;&nbsp;</span>{$v.intentional_grade_text}&nbsp;&nbsp;{/if}
                                                                    {if $v.next_follow_up_time}<span style="font-weight: bold;">下次联系时间:&nbsp;&nbsp;</span>{$v.next_follow_up_time}&nbsp;&nbsp;{/if}
                                                                </p>
                                                                {/if}
                                                            </div>
                                                        </div>
                                                    </li>
                                                    {/volist}
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--底部公共部分-->
<script type="text/javascript" src="/crm/js/jquery.min.js"></script>
<script type="text/javascript" src="/crm/js/voip.js"></script>
<script type="text/javascript" src="/crm/js/jquery.md5.js"></script>
<script type="text/javascript" src="/crm/js/voiptext.js"></script>
{include file="common/footer" /}
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'rate','form','laydate'], function(){
        let rate = layui.rate;
        let form = layui.form;
        let laydate = layui.laydate;
        let grade = $("#grade").val();
        let student_id = $("#student_id").val();
        let date = "{$date}";
        let phone = "{$student.phone}";

        $('#call').click(function () {
            /*标为无效*/
            layer.open({
                type: 2,
                skin: 'layui-layer-lan',
                closeBtn: 2,
                title: '八百呼',
                area: ['80%', '80%'],
                shadeClose: false,
                content: "{:url('Customer/outbound_call')}?phone=" + phone,
            });
        });

        //下次跟进日期
        laydate.render({
            elem: '#gj'
            ,type:'datetime'
            ,min: date
            ,trigger: 'click'
        });
        $(function(){
            //给所有的td添加点击事件
            $('.sex').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    var sex = '';
                    if(newText == '男'){
                        sex = 1;
                    }else if(newText == '女'){
                        sex = 2;
                    }
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"sex="+sex,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.customer_name').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"customer_name="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.guardian_phone').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"guardian_phone="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.other').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"other="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.other_phone').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"other_phone="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.qq').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"qq="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
            $('.weixin').click(function(){
                //获得当前点击的对象
                var td=$(this);
                //取出当前td的文本内容保存起来
                var oldText=td.text();
                //建立一个文本框，设置文本框的值为保存的值
                var input=$("<input type='text' value='"+oldText+"'/>");
                //alert(oldText);
                //将当前td对象内容设置为input
                td.html(input);
                //设置文本框的点击事件失效
                input.click(function(){
                    return false;
                });
                //设置文本框的样式
                input.css("border-width","0");
                input.css("font-size","16px");
                input.css("text-align","left");
                //设置文本框宽度等于td的宽度
                input.width(td.width());
                //当文本框失去焦点时重新变为文本
                input.blur(function(){
                    var input_blur=$(this);
                    //保存当前文本框的内容
                    var newText=input_blur.val();
                    //异步保存
                    $.ajax({
                        type:"POST",
                        url: "{:url('Customer/edit')}?id=" + student_id,
                        data:"weixin="+newText,
                        success:function(res){
                            if (res.code === 0) {

                            } else {

                            }
                        }
                    });
                    td.html(newText);
                });
            });
        });

        form.on('submit(formDemo)', function(data){
            $.ajax({
                url: "{:url('Customer/addFollowUp')}",
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    if (res.code === 1) {
                        layer.msg(res.msg, {icon: 1, time: res.wait * 1000}, function () {
                            let index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);  // 关闭layer
                            // window.parent.location.reload(); //刷新父页面
                        });
                    } else {
                        layer.msg(res.msg, {icon: 2, time: res.wait * 1000}, function () {
                            // window.location.reload();
                        });
                    }
                },
            });
            return false;
        });

        let active = {
            assignment: function () {
                /*转给同事*/
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '转给同事',
                    area: ['60%', '400px'],
                    shadeClose: false,
                    btnAlign: 'c',
                    shade: 0,
                    content: "{:url('Customer/assignment')}?ids=" + student_id,
                });
            },
            invalid: function () {
                /*标为无效*/
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '标记无效',
                    area: ['40%', '320px'],
                    shadeClose: false,
                    content: "{:url('Customer/invalid')}?ids=" + student_id,
                });
            },
            release: function () {
                /*释放线索*/
                layer.open({
                    type: 2,
                    skin: 'layui-layer-lan',
                    closeBtn: 2,
                    title: '释放客户',
                    area: ['40%', '320px'],
                    shadeClose: false,
                    content: "{:url('Customer/release')}?ids=" + student_id,
                });
            },
            delete: function () {
                /*释放线索*/
                let data = {"ids": student_id};
                let url = '{:url("Customer/delete")}';

                layer.confirm('<span style="color: #666666">选中的客户将被移除,并且无法恢复，确认删除吗?</span>',{ title: "移除客户" },function (index) {
                    layer.close(index);
                    $.post(url,data,function(response){
                        if(response.code === 1){
                            layer.msg(response.msg, {icon: 1, time: response.wait * 1000},function () {
                                let index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                parent.layer.close(index);  // 关闭layer
                                window.parent.location.reload(); //刷新父页面
                            });
                        }
                    });
                });
            },
        };

        $('.layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
